﻿namespace WMS6.Web.Outbound
{
    using System;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BaseInfoDetailServiceRef;
    using WMS6.Web.OutboundServiceRef;
    using WMS6.Web.UserControls;

    public class ShippingDetail : BasePage
    {
        protected Button btnCancel;
        protected DropDownList ddlAllocateRule;
        protected DropDownList ddlPreAllocateRuleID;
        protected DropDownList ddlSkuRotation;
        protected DropDownList ddlStatus;
        protected DropDownList ddlUomID;
        protected HtmlForm F7063;
        protected HtmlInputHidden hdncalendarFlag;
        protected HtmlInputHidden hdnDataFormat;
        protected HiddenField hdnExpiryDate;
        protected HiddenField hdnExternal;
        protected HtmlInputHidden hdnFrom;
        protected HiddenField hdnLot1;
        protected HiddenField hdnLot10;
        protected HiddenField hdnLot2;
        protected HiddenField hdnLot3;
        protected HiddenField hdnLot4;
        protected HiddenField hdnLot5;
        protected HiddenField hdnLot6;
        protected HiddenField hdnLot7;
        protected HiddenField hdnLot8;
        protected HiddenField hdnLot9;
        protected HtmlInputHidden hdnOrderID;
        protected HtmlInputHidden hdnOwnerID;
        protected HiddenField hdnProductDate;
        protected HtmlInputHidden hdnSkuID;
        protected HtmlInputHidden hdnType;
        protected Label lblAllocatedQty;
        protected Label lblAllocateRuleDetail;
        protected Label lblAllocateRuleID;
        protected Label lblExternLineID;
        protected Label lblLineID;
        protected Label lblMsg;
        protected Label lblOriginalQty;
        protected Label lblPackedQty;
        protected Label lblPackingID;
        protected Label lblPickingInstructions;
        protected Label lblPreallocatedQty;
        protected Label lblPreallocateRuleID;
        protected Label lblRemark;
        protected Label lblShippedQty;
        protected Label lblSkuDesrc;
        protected Label lblSkuID;
        protected Label lblSkuRoTation;
        protected Label lblStatus;
        protected Label lblUdf1;
        protected Label lblUdf10;
        protected Label lblUdf2;
        protected Label lblUdf3;
        protected Label lblUdf4;
        protected Label lblUdf5;
        protected Label lblUdf6;
        protected Label lblUdf7;
        protected Label lblUdf8;
        protected Label lblUdf9;
        protected Label lblUomID;
        protected LotAtrributeCtrl LotAtrributeCtrl1;
        protected HtmlLink mycss;
        protected Label one1;
        protected Label one2;
        protected TextBox txtAllocatedQty;
        protected TextBox txtExternLineID;
        protected TextBox txtLineID;
        protected TextBox txtOriginalQty;
        protected TextBox txtPackedQty;
        protected TextBox txtPackID;
        protected TextBox txtPickingInstuctions;
        protected TextBox txtPreallocatedQty;
        protected TextBox txtRemark;
        protected TextBox txtShippedQty;
        protected TextBox txtSkuDesrc;
        protected TextBox txtSkuID;
        protected TextBox txtUdf1;
        protected TextBox txtUdf10;
        protected TextBox txtUdf2;
        protected TextBox txtUdf3;
        protected TextBox txtUdf4;
        protected TextBox txtUdf5;
        protected TextBox txtUdf6;
        protected TextBox txtUdf7;
        protected TextBox txtUdf8;
        protected TextBox txtUdf9;

        private void BindData2UomList(string packID)
        {
            try
            {
                base.BindUomList2DDL(this.ddlUomID, packID);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F7600_012") + ex.Message;
                this.txtPackID.Focus();
            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            base.Server.Transfer(string.Format("Shipping.aspx?from={0}&detail={1}&ID={2}", base.UrlEncode(this.hdnFrom.Value), "2", base.UrlEncode(this.hdnOrderID.Value.Trim())));
        }

        private void LoadData()
        {
            this.txtLineID.Enabled = false;
            base.BindData2DDLByRules(this.ddlPreAllocateRuleID, "PreallocateRule");
            base.BindData2DDLByRules(this.ddlAllocateRule, "AllocateRule");
            base.BindData2DDLByRules(this.ddlSkuRotation, "RotationRule");
            base.BindData2DDLBySysCode(this.ddlStatus, "OrderStatus");
            if (!string.IsNullOrEmpty(base.Request.QueryString["ID"]))
            {
                string orderID = base.Request.QueryString["ID"];
                this.hdnOrderID.Value = orderID;
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                string from = base.Request.QueryString["from"];
                this.hdnFrom.Value = from;
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["LineID"]))
            {
                string LineID = base.Request.QueryString["LineID"];
                this.txtLineID.Text = LineID;
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["OwnerID"]))
            {
                string ownerID = base.Request.QueryString["OwnerID"];
                this.hdnOwnerID.Value = ownerID;
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["SkuID"]))
            {
                string SkuID = base.Request.QueryString["SkuID"];
                this.txtSkuID.Text = SkuID;
                this.hdnSkuID.Value = SkuID;
            }
            this.setShippingOrderDetail2From();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
            this.LotAtrributeCtrl1.LoadData(this.hdnSkuID.Value, this.hdnOwnerID.Value, this.LotAtrributeCtrl1.ClientID.ToString(), false, 4);
        }

        private void setShippingOrderDetail2From()
        {
            if (((!string.IsNullOrEmpty(this.hdnOrderID.Value) && !string.IsNullOrEmpty(this.txtLineID.Text)) && !string.IsNullOrEmpty(this.txtSkuID.Text)) && !string.IsNullOrEmpty(this.hdnOwnerID.Value))
            {
                OrderDetailInfo orderDetail = OutboundServiceClientProxy.GetInstance().GetShippingOrderDetailByID(this.hdnOrderID.Value, this.txtLineID.Text);
                if (orderDetail != null)
                {
                    this.ddlStatus.SelectedValue = orderDetail.Status;
                    this.txtExternLineID.Text = orderDetail.ExternLineID;
                    SkuInfo skuInfo = BaseInfoDetailServiceClientProxy.GetInstance().GetDetailInfoByID(this.hdnOwnerID.Value, this.txtSkuID.Text, "", "SKU") as SkuInfo;
                    if (!(((skuInfo == null) || string.IsNullOrEmpty(skuInfo.SkuID)) || string.IsNullOrEmpty(skuInfo.OwnerID)))
                    {
                        this.txtSkuDesrc.Text = skuInfo.Descr;
                        this.txtPackID.Text = skuInfo.PackID;
                        this.ddlPreAllocateRuleID.SelectedValue = skuInfo.PreallocateRuleID;
                        this.ddlAllocateRule.SelectedValue = skuInfo.AllocateRuleID;
                        this.ddlSkuRotation.SelectedValue = skuInfo.RotationRuleID;
                        this.BindData2UomList(this.txtPackID.Text.Trim());
                    }
                    this.txtOriginalQty.Text = base.GetPreferenceDigit(orderDetail.OriginalQty);
                    this.txtPreallocatedQty.Text = base.GetPreferenceDigit(orderDetail.PreallocatedQty);
                    this.txtAllocatedQty.Text = base.GetPreferenceDigit(orderDetail.AllocatedQty);
                    this.txtPackedQty.Text = base.GetPreferenceDigit(orderDetail.PickedQty);
                    this.txtShippedQty.Text = base.GetPreferenceDigit(orderDetail.ShippedQty);
                    this.txtUdf1.Text = orderDetail.Udf1;
                    this.txtUdf2.Text = orderDetail.Udf2;
                    this.txtUdf3.Text = orderDetail.Udf3;
                    this.txtUdf4.Text = orderDetail.Udf4;
                    this.txtUdf5.Text = orderDetail.Udf5;
                    this.txtUdf6.Text = orderDetail.Udf6;
                    this.txtUdf7.Text = orderDetail.Udf7;
                    this.txtUdf8.Text = orderDetail.Udf8;
                    this.txtUdf9.Text = orderDetail.Udf9;
                    this.txtUdf10.Text = orderDetail.Udf10;
                    this.txtRemark.Text = orderDetail.Remark;
                    this.hdnLot1.Value = orderDetail.LotAttr01;
                    this.hdnLot2.Value = orderDetail.LotAttr02;
                    this.hdnLot3.Value = orderDetail.LotAttr03;
                    this.hdnLot4.Value = orderDetail.LotAttr04;
                    this.hdnLot5.Value = orderDetail.LotAttr05;
                    this.hdnLot6.Value = orderDetail.LotAttr06;
                    this.hdnLot7.Value = orderDetail.LotAttr07;
                    this.hdnLot8.Value = orderDetail.LotAttr08;
                    this.hdnLot9.Value = orderDetail.LotAttr09;
                    this.hdnLot10.Value = orderDetail.LotAttr10;
                    this.hdnExpiryDate.Value = base.GetPreferenceShortDate(orderDetail.ExpiryDate);
                    this.hdnProductDate.Value = base.GetPreferenceShortDate(orderDetail.ProduceDate);
                    this.hdnExternal.Value = orderDetail.ExternalLot;
                }
            }
        }

        protected void txtPackID_TextChanged(object sender, EventArgs e)
        {
            this.BindData2UomList(this.txtPackID.Text.Trim());
        }

        protected void txtSkuID_TextChanged(object sender, EventArgs e)
        {
            try
            {
                string skuID = this.txtSkuID.Text.Trim();
                SkuInfo skuInfo = BaseInfoDetailServiceClientProxy.GetInstance().GetDetailInfoByID(this.hdnOwnerID.Value, skuID, "", "SKU") as SkuInfo;
                if (!(((skuInfo == null) || string.IsNullOrEmpty(skuInfo.SkuID)) || string.IsNullOrEmpty(skuInfo.OwnerID)))
                {
                    this.txtSkuDesrc.Text = skuInfo.Descr;
                    this.txtPackID.Text = skuInfo.PackID;
                    this.ddlPreAllocateRuleID.SelectedValue = skuInfo.PreallocateRuleID;
                    this.ddlAllocateRule.SelectedValue = skuInfo.AllocateRuleID;
                    this.ddlSkuRotation.SelectedValue = skuInfo.RotationRuleID;
                    this.BindData2UomList(this.txtPackID.Text.Trim());
                }
                else
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F7600_013");
                    this.txtSkuID.Focus();
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }
    }
}

